<?php

namespace app\common\service;

use app\common\exception\BusinessException;
use app\common\helper\WxBizDataHelper;
use app\common\helper\WxHelper;
use Firebase\JWT\ExpiredException;
use Firebase\JWT\JWT;
use think\facade\Config;
use Firebase\JWT\SignatureInvalidException;
use think\Exception;

class UserShareImageService
{

    /**
     * create
     * @param $uid
     * @return string
     * @throws BusinessException
     * @throws Exception
     */
    public function create($appId, $uid): string
    {
        // 设置分享路径|场景
        $path = '/pages/index/city/city';
        $scene = 'agent_id=' . $uid;

        // 获取accessToken
        $wx = new WxService();
        $wx->setAppId($appId);
        $access_token = $wx->getAccessToken();

        // 生成宣传素材
        $binData = WxHelper::createWxQrcode($access_token, $path, $scene);

        // 上传文件到Oss文件服务器
        $app = 'learnAppUserShare';
        $suffix = 'image/png';
        $ossService = new OssService($app);
        return $ossService->uploadBin($binData, $suffix);
    }
}